<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>竖向滑屏</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            overflow: hidden;
        }

        #content {
            height: 3000px;
            width: 100%;
            background: linear-gradient(to bottom, #ecf, rgb(96, 9, 104));
            position: absolute;
            left: 0;
            top: 0;
        }
    </style>
</head>

<body>
    <div id="app">
        <div id="content">xxxxx</div>
    </div>

    <script>
        //获取元素
        let app = document.querySelector('#app');
        let content = document.querySelector('#content');

        //默认行为
        app.addEventListener('touchstart', function (e) {
            e.preventDefault();
        });

        content.addEventListener('touchstart', function (e) {
            //获取起始点的垂直方向的偏移量
            this.y = e.changedTouches[0].clientY;
            this.t = content.offsetTop;
            this.style.transition = 'none';
        });

        content.addEventListener('touchmove', function (e) {
            this._y = e.changedTouches[0].clientY;

            // this._y - this.y = x - this.t
            this.newTop = this._y - this.y + this.t;
            //设置样式
            this.style.top = this.newTop + 'px';
        });

        content.addEventListener('touchend', function (e) {
            this.style.transition = 'top 0.5s cubic-bezier(0, 0.49, 0.51, 1.57)';
            
            //判断
            if(this.newTop >= 0){
                this.style.top = '0px';
            }
        });

    </script>
</body>

</html>